import { HttpExceptionFilter } from './filter/http-exception.filter';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import * as cookieParser from 'cookie-parser';
import * as session from 'express-session';
import config from './config/config';
import * as path from 'path';
async function bootstrap() {
    const app = await NestFactory.create<NestExpressApplication>(AppModule);
    app.useStaticAssets(path.join(__dirname, '../public'), {
        prefix: '/assets',
    });
    app.useStaticAssets(path.join(__dirname, '../client'));
    app.use(cookieParser(config.cookieSecret));
    app.enableCors({
        origin: (req, next) => {
            next(null, config.corsRegExp);
        },
        credentials: true,
    });
    app.use(
        session({
            secret: config.sessionSecret,
            cookie: config.sessionCookie,
            resave: true,
            saveUninitialized: true,
            rolling: true,
        }),
    );
    app.useGlobalFilters(new HttpExceptionFilter());
    await app.listen(3001);
}
bootstrap();
